/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author David
 */
@Entity
@Table(name = "abono")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Abono.findAll", query = "SELECT a FROM Abono a"),
    @NamedQuery(name = "Abono.findById", query = "SELECT a FROM Abono a WHERE a.id = :id"),
    @NamedQuery(name = "Abono.findByNom", query = "SELECT a FROM Abono a WHERE a.nom = :nom"),
    @NamedQuery(name = "Abono.findByComposicio", query = "SELECT a FROM Abono a WHERE a.composicio = :composicio"),
    @NamedQuery(name = "Abono.findByQuantitatPaquet", query = "SELECT a FROM Abono a WHERE a.quantitatPaquet = :quantitatPaquet")})
public class Abono implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "nom")
    private String nom;
    @Column(name = "composicio")
    private String composicio;
    @Lob
    @Column(name = "img")
    private byte[] img;
    @Basic(optional = false)
    @Column(name = "quantitat_paquet")
    private int quantitatPaquet;
    @JoinColumn(name = "unitats_quantitat", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private UnitatsMesura unitatsQuantitat;
    @JoinColumn(name = "unitats_paquet", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private UnitatsMesura unitatsPaquet;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "abonoId")
    private Collection<Abonat> abonatCollection;

    public Abono() {
    }

    public Abono(Integer id) {
        this.id = id;
    }

    public Abono(Integer id, String nom, int quantitatPaquet) {
        this.id = id;
        this.nom = nom;
        this.quantitatPaquet = quantitatPaquet;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getComposicio() {
        return composicio;
    }

    public void setComposicio(String composicio) {
        this.composicio = composicio;
    }

    public byte[] getImg() {
        return img;
    }

    public void setImg(byte[] img) {
        this.img = img;
    }

    public int getQuantitatPaquet() {
        return quantitatPaquet;
    }

    public void setQuantitatPaquet(int quantitatPaquet) {
        this.quantitatPaquet = quantitatPaquet;
    }

    public UnitatsMesura getUnitatsQuantitat() {
        return unitatsQuantitat;
    }

    public void setUnitatsQuantitat(UnitatsMesura unitatsQuantitat) {
        this.unitatsQuantitat = unitatsQuantitat;
    }

    public UnitatsMesura getUnitatsPaquet() {
        return unitatsPaquet;
    }

    public void setUnitatsPaquet(UnitatsMesura unitatsPaquet) {
        this.unitatsPaquet = unitatsPaquet;
    }

    @XmlTransient
    public Collection<Abonat> getAbonatCollection() {
        return abonatCollection;
    }

    public void setAbonatCollection(Collection<Abonat> abonatCollection) {
        this.abonatCollection = abonatCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Abono)) {
            return false;
        }
        Abono other = (Abono) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Abono[ id=" + id + " ]";
    }
    
}
